import yql
from yql import ThreeLegged

class TriPeh(ThreeLegged):
    def __init__(self):
        AK = "dj0yJmk9WjNaQkoxdDZyanJ2JmQ9WVdrOVYyTjNkMFJYTm1jbWNHbzlNVE13TWpBd05EVS0mcz1jb25zdW1lcnNlY3JldCZ4PWQ0"
        SK = "9d8c16493dfc5de7010f9cd173e91cb82d63f924"
        super(TriPeh, self).__init__(AK, SK)
        self.pica_longa = None
        self.yleftleg = None
        self.uauth = None
        self.urightleg  = None

    def _getleg(self):
        if self.yleftleg == None or self.uauth == None:
            self.yleftleg, self.uauth = self.get_token_and_auth_url()

    def __refreshedToken__():
        if self.check_token(self.pica_longa):
            self.refresh_token(self.pica_longa)

    def getYuri(self):
        self._getleg()
        return self.uauth

    def getYleg(self):
        self._getleg()
        return self.yleftleg

    def setUleg(self, uleg):
        self.uleg = uleg
        self.pica_longa = self.get_access_token(self.yleftleg, uleg)
        return self

    def setAccessToken(self, uDick):
        self.pica_long = uDick
        return self

    def getAccessToken(self):
        if self.pica_longa == None:
            return None
        self.__refreshedToken__()
        return self.pica_longa

    def execute(self, query, para = ""):
        self.__refreshedToken__()
        return super(TriPeh, self).execute(query, para, self.pica_longa)

if __name__ == "__main__":
    piro = TriPeh()
    print piro.getYuri()
    tk = raw_input("token:?")
    piro.setUleg(tk)
    dir(piro.execute("select * from meme.user.dashboard"))
    print "\n"
    dir(piro.execute("select * from meme.posts(2) where owner_guid = me"))